import {
	CAROUSEL,
	SERIESLESSON,
	FACETOFACELESSON,
	SERIESCLASSTOP,
	TABS,
	DETAIL_HEAD,
	DETAIL_BASEINFO,
	DETAIL_MYSERVICE,
	DETAIL_TEACHERTEAM,
	DETAIL_TUTORTEAM,
	DETAIL_LEARNINGMODE,
	DETAIL_STAGE,
	DETAIL_LEAVEMSG,
	DETAIL_QUESTION,

	WHATISLIGHTLESSON,
	SYNCLESSON,
	FACETOFACE,
	PLAYER,
	OFFLINETEACH,
	MYCLASSMATE_INFO,
	TEACHERINFO,
	OUTLINEINFO,
	TESTINFO,
	DATAINFOS,
	ORCODE,

	LABELS,
	ITEMLIST,
	TUTORRIALINFO,
	TABBAR,
} from './method-type.js';
import req from './requestMethod';
export default {
	//通用服务器数据请求函数
	
	async reqServerData({commit,state},params) {  //actions独立命名函数 state内部有可以获取参数
	
		let result = await req.reqMethod(params)			//进行请求
		
		
		if (result.status === 200) {	//判断返回结果
			// const address = result.data		//结果提取

			switch (params.methodName) {		//methodName本身就是一个常量的标志也是函数名
				case CAROUSEL:
					commit(CAROUSEL, result.data)	//数据提交vuex
					console.log('更新了:'+CAROUSEL)
					break;

				case SERIESLESSON:
					commit(SERIESLESSON, result.data)
					console.log('更新了:'+SERIESLESSON)
					break;

				case FACETOFACELESSON:
					commit(FACETOFACELESSON, result.data)
					console.log('更新了:'+FACETOFACELESSON)
					break;
				case SERIESCLASSTOP:
					commit(SERIESCLASSTOP, result.data)
					console.log('更新了:'+SERIESCLASSTOP)
					break;
				case TABS:
					commit(TABS, result.data)
					console.log('更新了:'+TABS)
					break;
				case DETAIL_HEAD:
					commit(DETAIL_HEAD, result.data)
					console.log('更新了:'+DETAIL_HEAD)
					break;
				case DETAIL_BASEINFO:
					commit(DETAIL_BASEINFO, result.data)
					console.log('更新了:'+DETAIL_BASEINFO)
					break;
				case DETAIL_MYSERVICE:
					commit(DETAIL_MYSERVICE, result.data)
					console.log('更新了:'+DETAIL_MYSERVICE)
					break;
				case DETAIL_TEACHERTEAM:
					commit(DETAIL_TEACHERTEAM, result.data)
					console.log('更新了:'+DETAIL_TEACHERTEAM)
					break;
				case DETAIL_TUTORTEAM:
					commit(DETAIL_TUTORTEAM, result.data)
					console.log('更新了:'+DETAIL_TUTORTEAM)
					break;
				case DETAIL_LEARNINGMODE:
					commit(DETAIL_LEARNINGMODE, result.data)
					console.log('更新了:'+DETAIL_LEARNINGMODE)
					break;
				case DETAIL_STAGE:
					commit(DETAIL_STAGE, result.data)
					console.log('更新了:'+DETAIL_STAGE)
					break;
				case DETAIL_LEAVEMSG:
					commit(DETAIL_LEAVEMSG, result.data)
					console.log('更新了:'+DETAIL_LEAVEMSG)
					break;
				case DETAIL_QUESTION:
					commit(DETAIL_QUESTION, result.data)
					console.log('更新了:'+DETAIL_QUESTION)
					break;

				case WHATISLIGHTLESSON:
					commit(WHATISLIGHTLESSON, result.data)
					console.log('更新了:'+WHATISLIGHTLESSON)
					break;
				case SYNCLESSON:
					commit(SYNCLESSON, result.data)
					console.log('更新了:'+SYNCLESSON)
					break;
				case FACETOFACE:
					commit(FACETOFACE, result.data)
					console.log('更新了:'+FACETOFACE)
					break;
				case PLAYER:
					commit(PLAYER, result.data)
					console.log('更新了:'+PLAYER)
					break;
				case OFFLINETEACH:
					commit(OFFLINETEACH, result.data)
					console.log('更新了:'+OFFLINETEACH)
					break;
				case MYCLASSMATE_INFO:
					commit(MYCLASSMATE_INFO, result.data)
					console.log('更新了:'+MYCLASSMATE_INFO)
					break;
				case TEACHERINFO:
					commit(TEACHERINFO, result.data)
					console.log('更新了:'+TEACHERINFO)
					break;
				case OUTLINEINFO:
					commit(OUTLINEINFO, result.data)
					console.log('更新了:'+OUTLINEINFO)
					break;
				case TESTINFO:
					commit(TESTINFO, result.data)
					console.log('更新了:'+TESTINFO)
					break;
				case DATAINFOS:
					commit(DATAINFOS, result.data)
					console.log('更新了:'+DATAINFOS)
					break;
				case ORCODE:
					commit(ORCODE, result.data)
					console.log('更新了:'+ORCODE)
					break;

				case LABELS:
					commit(LABELS, result.data)
					console.log('更新了:'+LABELS)
					break;
				case ITEMLIST:
					commit(ITEMLIST, result.data)
					console.log('更新了:'+ITEMLIST)
					break;
				case TUTORRIALINFO:
					commit(TUTORRIALINFO, result.data)
					console.log('更新了:'+TUTORRIALINFO)
					break;
				case TABBAR:
					commit(TABBAR, result.data[0])
					console.log('更新了:'+TABBAR)
					break;
			}
			//result.data.status==0为成功 1失败
		}else if(result.data.status == 0){

			console.log('数据插入成功')
		}else{
			console.log('没有什么数据可更新vuex的')
		}
	},

}

// param:{
// 	params:[],
// 	method:'', //get,post
// 	methodName:'',
// 	

// }


// APP.vue中mounted()中调用
// 	this.$store.dispatch('getAddress')  //$store.dispatch这个是异步调用的
//  store.dispatch('incrementAsync', {amount: 10})
// store.dispatch('actionA').then(() => {
//     // ...
//   })
// -----------------------------------------------
// 	另一种调用方法
// 	methods:{
// 		...mapActions(['getAddress'])
// 	}
// 	然后在this.getAddress()方式调用map中的方法
// -----------------------------------------------
// 	import {mapState} from 'vuex'
// 	通过计算属性
// 	computed:{
// 		...mapState(['address','categroys',....])   //这种方式 课直接获取vuex中的state数据
// 	}
// 	然后组件上绑定 :title = "address.name"
// -----------------------------------------------
// 思路步骤
// 首先app 提交(this.$store.dispatch)->actions.js 拼接参数请求API接口->调用ajax函数名->ajax函数内部实现->返回到actions.js中->判断返回结果 提交->mutations.js中常量函数->设置给state.js
